<?php
class Bap_sign_model extends MY_Model {
	
    function Bap_sign_model (){
        parent::MY_Model();
        $this->load->database();
        $this->table_name = "bap_sign";
        $this->table_fields = array('bap_id','kary_id','bap_sign_type','bap_sign_signing');
    }
    
    function select_last_entry($search_key=false, $where=false, $limit=10, $offset=0, $orderby=""){
    }
        
    function select_by_id($bap_id, $kary_id){
    	return $query = $this->db->get_where($this->table_name, array('bap_id' => $bap_id, 'kary_id'=>$kary_id));
    }
    
//    function get_last_entry(){
//    	$this->select_max('bap_saksi_id');
//    	return $this->get()->row();
//    }

    function select_by_bap($bap_id){
    	return $this->get_where(array('bap_id' => $bap_id));
    }
    
    function select_by_perbID($perb_id){
    	$this->join('bap', 'bap.bap_id='.$this->table_name.'.bap_id');
    	return $this->get_where("perb_id='$perb_id'");
    }
    
    function sign($bapID, $karyID, $type){
    	return $this->update(
    		array('bap_id'=>$bapID, 'kary_id'=>$karyID, 'bap_sign_type'=>$type),
    		 array('bap_sign_signing'=>md5($karyID))
    	);
    }
    
    function has_give_sign($bapID, $karyID){
    	$res = $this->get_where(array('bap_id'=>$bapID, 'kary_id'=>$karyID))->row();
    	return $res->bap_sign_signing? $res->bap_sign_signing != NULL : false;
    }
}